package com.pers.springcloud.controller;

import com.pers.springcloud.entities.JSONResult;
import com.pers.springcloud.entities.Payment;
import com.pers.springcloud.service.PaymentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: 黄建
 * @Date: 2020/3/6 18:23
 */
@RestController
@Slf4j
@RequestMapping(value = "/payment")
public class PaymentController {

    @Value("${server.port}")
    private String serverPort;

    @Autowired
    private PaymentService paymentService;

    @PostMapping(value = "/create")
    public JSONResult create(@RequestBody Payment payment){
        Long aLong = paymentService.create(payment);
        if (aLong==0){
            return JSONResult.error("插入失败");
        }
        return JSONResult.success(serverPort,aLong);
    }

    @GetMapping(value = "/get/{id}")
    public JSONResult getPayment(@PathVariable(value = "id") Long id){
        Payment payment = paymentService.getPaymentById(id);
        return JSONResult.success(serverPort,payment);
    }

    @GetMapping(value = "/lb")
    public String getPaymentLb() {
        return serverPort;
    }

}
